package cn.qicaiwang.open.app.controller;

import cn.qicaiwang.open.app.entity.MembershipPlan;
import cn.qicaiwang.open.app.server.MembershipPlanService;
import cn.qicaiwang.open.common.response.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 会员套餐控制器
 */
@RestController
@RequestMapping("/qcwapp/plans")
public class MembershipPlanController {
    @Autowired
    private MembershipPlanService membershipPlanService;

    /**
     * 创建会员套餐
     * @param plan 会员套餐实体
     * @return 创建的会员套餐
     */
    @PostMapping
    public ResponseResult<MembershipPlan> createPlan(@RequestBody MembershipPlan plan) {
        MembershipPlan createdPlan = membershipPlanService.createPlan(plan);
        return ResponseResult.ok(createdPlan);
    }

    /**
     * 更新会员套餐
     * @param id 套餐ID
     * @param plan 会员套餐实体
     * @return 更新后的会员套餐
     */
    @PutMapping("/{id}")
    public ResponseResult<MembershipPlan> updatePlan(@PathVariable Long id, @RequestBody MembershipPlan plan) {
        plan.setId(id);
        MembershipPlan updatedPlan = membershipPlanService.updatePlan(plan);
        return ResponseResult.ok(updatedPlan);
    }

 /*   *//**
     * 删除会员套餐
     * @param id 套餐ID
     * @return 204 No Content
     *//*
    @DeleteMapping("/{id}")
    public ResponseResult<Void> deletePlan(@PathVariable Long id) {
        membershipPlanService.deletePlan(id);
        return ResponseResult.noContent().build();
    }*/

    /**
     * 获取会员套餐详情
     * @param id 套餐ID
     * @return 会员套餐实体
     */
    @GetMapping("/{id}")
    public ResponseResult<MembershipPlan> getPlanById(@PathVariable Long id) {
        MembershipPlan plan = membershipPlanService.getPlanById(id);
        return ResponseResult.ok(plan);
    }

    /**
     * 获取所有会员套餐
     * @return 会员套餐列表
     */
    @GetMapping
    public ResponseResult<List<MembershipPlan>> getAllPlans() {
        List<MembershipPlan> plans = membershipPlanService.getAllPlans();
        return ResponseResult.ok(plans);
    }

    /**
     * 获取所有启用的会员套餐
     * @return 启用的会员套餐列表
     */
    @GetMapping("/active")
    public ResponseResult<List<MembershipPlan>> getActivePlans() {
        List<MembershipPlan> plans = membershipPlanService.getActivePlans();
        return ResponseResult.ok(plans);
    }
}